package com.bier.fishproject.adapter;

import java.util.List;
import com.bier.fishproject.R;
import com.bier.fishproject.entity.Water;
import com.bier.fishproject.utils.Base64Str;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class WaterListAdapter extends BaseAdapter{
	
	private Context context;
	private List<Water> list;
	private Water w;
	public WaterListAdapter(Context context,List<Water> list) {
		super();
		this.context = context;
		this.list=list;
	}

	@Override
	public int getCount() {
		return list==null ? 0 : list.size();
	}

	@Override
	public Object getItem(int position) {
		return position;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View view, ViewGroup parent) {
		ViewHolder holder = null;
		if(view==null){
			holder = new ViewHolder(); 
			view = LayoutInflater.from(context).inflate(R.layout.water_item, null);
			holder.tvStatus=(TextView)view.findViewById(R.id.tv_wi_status);
			holder.tvCode=(TextView)view.findViewById(R.id.tv_wi_code);
			holder.tvName=(TextView)view.findViewById(R.id.tv_wi_name);
			holder.tvReckon=(TextView)view.findViewById(R.id.tv_wi_reckon);
			holder.tvStartTime=(TextView)view.findViewById(R.id.tv_wi_startTime);
			holder.tvSecond=(TextView)view.findViewById(R.id.tv_wi_second);
			holder.tvAt=(TextView)view.findViewById(R.id.tv_wi_at);
			holder.tvPrice=(TextView)view.findViewById(R.id.tv_wi_price);
			holder.tvNowAt=(TextView)view.findViewById(R.id.tv_wi_nowat);
			holder.tvApply=(TextView)view.findViewById(R.id.tv_wi_apply);
			holder.tvMoney=(TextView)view.findViewById(R.id.tv_wi_moneys);
			holder.tvHandle=(TextView)view.findViewById(R.id.tv_wi_handle);
			holder.tvPeiceAt=(TextView)view.findViewById(R.id.tv_wi_priceAt);
			view.setTag(holder);
		}else{
			holder=(ViewHolder)view.getTag();
		}
		w=list.get(position);
		if(w!=null){
			if(w.getDstatus().equals("0")){
				holder.tvStatus.setText("水表状态：正常");
			}else{
				holder.tvStatus.setText("水表状态：异常");
			}
			holder.tvCode.setText("水表编号："+w.getDid());
			holder.tvCode.setTag(w.getDid());
			holder.tvName.setText("水表名称："+Base64Str.getFromBase64(w.getDname()));
			if(w.getPaytype().equals("0")){
				holder.tvReckon.setText("计时");
			}else if(w.getPaytype().equals("1")){
				holder.tvReckon.setText("计量");
			}else if(w.getPaytype().equals("2")){
				holder.tvReckon.setText("智能");
			}
			if(!w.getStime().equals("0")){
				holder.tvStartTime.setText(w.getStime().substring(14, w.getStime().length()));
			}else{
				holder.tvStartTime.setText("0");
			}
			holder.tvSecond.setText(w.getUtime());
			holder.tvAt.setText(w.getStone());
			if(w.getPaytype().equals("0")){
				holder.tvPrice.setText(w.getPseconde());
				holder.tvPeiceAt.setText(R.string.priceAts);
			}else if(w.getPaytype().equals("1")){
				holder.tvPrice.setText(w.getPtone());
				holder.tvPeiceAt.setText(R.string.priceAt);
			}
			holder.tvNowAt.setText(w.getDreading());
			holder.tvApply.setText(w.getUtone());
			holder.tvMoney.setText(w.getTotal());
		}
		return view;
	}
	
	private class ViewHolder{
		TextView tvStatus,tvCode,tvName,tvReckon,tvStartTime,tvSecond,tvAt,tvPrice,tvNowAt,tvApply,tvMoney,tvHandle,tvPeiceAt;
	 }

}
